package com.mikufufu.blog.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mikufufu.blog.common.entity.AjaxResult;
import com.mikufufu.blog.model.dto.api.AlbumPageParam;
import com.mikufufu.blog.model.entity.Album;
import com.mikufufu.blog.model.vo.api.AlbumVO;
import com.mikufufu.blog.service.AlbumService;
import com.mikufufu.blog.utils.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "相册管理")
@RestController
@RequestMapping("/admin/album")
public class AlbumAdminController {

    @Autowired
    private AlbumService albumService;

    @ApiOperation(value = "添加相册", notes = "添加相册")
    @PostMapping("/add")
    public AjaxResult<Boolean> add(@RequestBody @Validated Album album) {
        return AjaxResult.data(albumService.save(album));
    }

    @ApiOperation(value = "修改相册", notes = "修改相册")
    @PutMapping("/update")
    public AjaxResult<Boolean> update(@RequestBody @Validated Album album) {
        return AjaxResult.data(albumService.updateById(album));
    }

    @ApiOperation(value = "分页查询相册列表", notes = "用于获取相册列表")
    @PostMapping("/page")
    public AjaxResult<IPage<AlbumVO>> page(@RequestBody @Validated AlbumPageParam param){
        return AjaxResult.data(albumService.getAlbumPage(param));
    }

    @ApiOperation(value = "获取相册详情", notes = "获取相册详情")
    @GetMapping("/detail")
    public AjaxResult<AlbumVO> detail(Integer id) {
        Album album = albumService.getById(id);
        return AjaxResult.data(BeanUtil.copy(album, AlbumVO.class));
    }
}
